 /***********************************************************
 *  File_Name  : XJXMLProfile.h
 *  File_Path   : 
 *  File_Encode : UTF8
 *  Description : XML配置文件读写类
 *  
 *  OS : Linux, UNIX
 *  LastVersion  : 20130723
 *      
 *  Author      : LiXiujie(李秀杰)
 *  Date        : 2013-7-23
 *  Version     : 20130723
 *  Description : 
 *                
 *  Edit Author : 
 *  Edit Date   : 
 *  Version     : 
 *  Description :
 *                
 ***********************************************************/
#ifndef XJXMLPROFILE_H_
#define XJXMLPROFILE_H_

#include <string>
#include <vector>

using namespace std;
namespace XJUtilClass {

class XJXMLProfileDataItem{
public:
	XJXMLProfileDataItem(){
		m_strCate = "Default";
		m_strName = "Default";
		m_strDesc = "";
		m_strValue = "";
	}
	XJXMLProfileDataItem(const string &strItemName, const string & strValue){
		m_strCate = "Default";
		m_strName = strItemName;
		m_strDesc = "";
		m_strValue = strValue;
	}
	XJXMLProfileDataItem(const string & strCategoryName, const string & strItemName, const string & strValue){
		m_strCate = strCategoryName;
		m_strName = strItemName;
		m_strValue = strValue;
	}
	XJXMLProfileDataItem(const string & strCategoryName, const string & strItemName, const string & strItemDesc, const string & strValue){
		m_strCate = strCategoryName;
		m_strName = strItemName;
		m_strDesc = strItemDesc;
		m_strValue = strValue;
	}
	XJXMLProfileDataItem(const XJXMLProfileDataItem &item){
		m_strCate = item.m_strCate;
		m_strName = item.m_strName;
		m_strDesc = item.m_strDesc;
		m_strValue = item.m_strValue;
	}
	XJXMLProfileDataItem& operator = (const XJXMLProfileDataItem &item){
		if (this == &item){
			return *this;
		}
		m_strCate = item.m_strCate;
		m_strName = item.m_strName;
		m_strDesc = item.m_strDesc;
		m_strValue = item.m_strValue;
		return *this;
	}
	const string &GetCate(){
		return m_strCate;
	}
	const string &GetName(){
		return m_strName;
	}
	const string &GetDesc(){
		return m_strDesc;
	}
	const string &GetValue(){
		return m_strValue;
	}

	XJXMLProfileDataItem& Set(const string & strItemName, const string & strValue){
		m_strName = strItemName;
		m_strValue = strValue;
		return *this;
	}
	XJXMLProfileDataItem& Set(const string & strCategoryName, const string & strItemName, const string & strValue){
		m_strCate = strCategoryName;
		m_strName = strItemName;
		m_strValue = strValue;
		return *this;
	}
	XJXMLProfileDataItem& SetCate(const string & strSrc){
		m_strCate = strSrc;
		return *this;
	}
	XJXMLProfileDataItem& SetName(const string & strSrc){
		m_strName = strSrc;
		return *this;
	}
	XJXMLProfileDataItem& SetDesc(const string & strSrc){
		m_strDesc = strSrc;
		return *this;
	}
	XJXMLProfileDataItem& SetValue(const string & strSrc){
		m_strValue = strSrc;
		return *this;
	}
public:
	string m_strCate;
	string m_strName;
	string m_strDesc;
	string m_strValue;
};

class XJXMLProfile {
public:
	XJXMLProfile();
	XJXMLProfile(const string &strFilePath);
	virtual ~XJXMLProfile();

	int AddItem(const XJXMLProfileDataItem &item);
	int SetItem(const XJXMLProfileDataItem &item);
	int DelItem(const string & strItemName);
	int DelItem(const string & strCategoryName, const string & strItemName);
	XJXMLProfileDataItem & GetItem(const string & strItemName);
	XJXMLProfileDataItem & GetItem(const string & strCategoryName, const string & strItemName);
	string &GetItemValue(const string & strItemName);
	string &GetItemValue(const string & strCategoryName, const string & strItemName);
	int ReadFile(const string &strFilePath);
	int WriteFile(const string &strFilePath);
	string &GetLastError();

	void Clear();
private:
	vector<XJXMLProfileDataItem > m_veDataItems;
	string m_strLastError;

	XJXMLProfileDataItem m_itemNull;
};

} /* namespace XJUtilClass */
#endif /* XJXMLPROFILE_H_ */
